package com.ruoyi.common.utils;

import cn.hutool.core.util.HexUtil;
import cn.hutool.crypto.BCUtil;
import cn.hutool.crypto.asymmetric.SM2;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;

/**
 * TODO SM2过密工具类
 *
 * @author 徐岩松
 * @version 1.0
 * Copyright: Copyright (c) 2023
 * @date 2023/7/28 15:07
 */
public class Sm2Utils {
    /**
     * 私钥签名
     *
     * @param privateKey 私钥
     * @param content    待签名内容
     * @return {@link String}
     */
    public static String sign(String privateKey, String content) {
        ECPrivateKeyParameters ecPrivateKeyParameters = BCUtil.toSm2Params(privateKey);
        //创建sm2 对象
        SM2 sm2 = new SM2(ecPrivateKeyParameters, null);
        return sm2.signHex(HexUtil.encodeHexStr(content));
    }

}
